# djangoProject/celery.py
import os
from celery import Celery

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangoProject.settings')
app = Celery('djangoProject')
app.config_from_object('django.conf:settings', namespace='CELERY')

# 配置
app.conf.broker_url = f"redis://{os.getenv('REDIS_HOST')}:6379/1"
app.conf.result_backend = f"redis://{os.getenv('REDIS_HOST')}:6379/2"
app.conf.task_default_rate_limit = '100/s'  # 限流
app.conf.worker_prefetch_multiplier = 4     # 优化预取

app.autodiscover_tasks()
